package pack0827;

import java.util.Collections;
import java.util.LinkedList;

public class DemoA {
    //LinkedList
    public static void a(){
        LinkedList<String> list = new LinkedList();
        list.add("aa");
        list.add("bb");
        list.add("cc");
        list.addFirst("dd");
        list.addLast("ee");
        System.out.println(list);

        /*list.remove("cc");
        list.remove(2);
        list.removeFirst();
        list.removeLast();
        System.out.println(list);*/

        list.set(3,"mm");
        String s1= list.get(2);
        String s2 = list.getFirst();
        String s3 = list.getLast();
        System.out.println(list);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);

        int size = list.size();
        System.out.println(size);

        Object[] array = list.toArray();
        for(int i = 0; i<array.length; i++){
            System.out.print(array[i]+"\t");
        }
        System.out.println("\n");
        for(int i = 0; i<list.size(); i++){
            System.out.print(list.get(i)+"\t");
        }
    }

    public static void b1(){
        LinkedList<Integer> list = new LinkedList<>();
        for(int i = 0; i<10; i++){
            list.add((int)(Math.random()*10));
        }
        int index1 = list.indexOf(1);
        int index2 = list.lastIndexOf(1);
        boolean b = list.contains(1);
        System.out.println(list);
        System.out.println(index1);
        System.out.println(index2);
        System.out.println(b);
    }

    public static void b2(){
        LinkedList<StuInfo> list = new LinkedList<>();
        StuInfo s1 = new StuInfo(1,"aa",23);
        StuInfo s2 = new StuInfo(2,"bb",22);
        StuInfo s3 = new StuInfo(3,"cc",25);
        list.add(s1);list.add(s2);list.add(s3);
        StuInfo s4 = s2;
        int index1 = list.indexOf(s4);
        int index2 = list.lastIndexOf(s4);
        boolean b = list.contains(s4);
        System.out.println(index1);
        System.out.println(index2);
        System.out.println(b);
    }
    //排序
    public static void c(){
        LinkedList<StuInfo> list = new LinkedList<>();
        StuInfo s1 = new StuInfo(1,"aa",23);
        StuInfo s2 = new StuInfo(2,"dd",22);
        StuInfo s3 = new StuInfo(3,"cc",25);
        list.add(s1);list.add(s2);list.add(s3);
        System.out.println(list);
        Collections.sort(list);
        System.out.println(list);
    }

    public static void main(String[] args) {
        c();
    }
}
